package com.zareal.ymcc.service.impl;

import com.zareal.ymcc.contants.TokenContants;
import com.zareal.ymcc.service.ICreatTokenCommonService;
import com.zareal.ymcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ICreatTokenCommonServiceImpl implements ICreatTokenCommonService {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public String getToken(String courseIds) {
        String token = StrUtils.getRandomString(8);
        // 登录id写死
        Long id = 3L;
        String key = String.format(TokenContants.ORDERTOKEN, courseIds, id);
        redisTemplate.opsForValue().set(key,token,30000, TimeUnit.SECONDS);
        return token;
    }
}
